package com.example.androidkotlinmvvm.xml

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.androidkotlinmvvm.mvvm.Data
import com.example.androidkotlinmvvm.mvvm.RetrofitClient
import kotlinx.coroutines.launch

class InfoListViewModel(): ViewModel() {
    private val userService = RetrofitClient.userService

    private val _user = MutableLiveData<Data>()
    val user: MutableLiveData<Data> = _user

    fun fetchUser() {
        viewModelScope.launch {
            try {
                val user = userService.getUsers()
                _user.value = user
            } catch (e: Exception) {
                // Handle error, e.g., show a message to the user
            }
        }
    }
}